package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    // 新增地址
    void insert(AddressBook addressBook);
    // 查询地址
    List<AddressBook> list(AddressBook addressBook);
    // 根据id查询地址
    @Select("select * from address_book where id = #{id}")
    AddressBook getById(Long id);
    // 设置默认地址
    @Update("update address_book set is_default = #{isDefault} where id = #{id}")
    void updateDefault(AddressBook addressBook);
    // 根据id删除地址
    @Delete("delete from address_book where id = #{id}")
    void delete(Long id);
    // 修改地址
    void update(AddressBook addressBook);
    // 根据用户id查询默认地址
    @Select("select * from address_book where user_id=#{userId} and is_default = #{isDefault}")
    AddressBook getBYDefault(AddressBook addressBook);
}
